import * as user from "./a.js";
import { b } from "./b.js";

console.log(user);
// console.log(a);
// console.log(b);
// console.log(import.meta);
// console.log(this);

// 柯里化固定参数数量
{
  function curry(f) {
    return function (a) {
      return function (b) {
        return f(a, b);
      };
    };
  }

  function sum(a, b) {
    return a + b;
  }

  const fn = curry(sum);

  console.log(fn(1)(2));
}

{
  function curry(f) {
    return function (...args) {
      // 包装函数的入参数量等于原函数的入参数量时，直接调用原函数
      if (args.length >= f.length) {
        return f.apply(this, args);
      } else {
        return function (...args2) {
          return curry(f)(...args, ...args2);
        };
      }
    };
  }

  function sum(a, b, c) {
    return a + b + c;
  }

  const fn = curry(sum);

  console.log(fn(1, 2, 3));
  console.log(fn(1)(2, 3));
  console.log(fn(1)(2)(3));
}
